hal_cc2530znp_target_board.h File Reference

public methods for hal_cc2530znp_target_board.c More...

#include "msp430x22x4.h"
#include "../Common/printf.h"
#include "../Common/utilities.h"

Defines

#define HAL_SLEEP()   ( __bis_SR_register(LPM3_bits + GIE))
#define HAL_WAKEUP()   ( __bic_SR_register_on_exit(LPM3_bits))
#define ENABLE_SRDY_INTERRUPT()   (P2IE |= BIT6)
#define DISABLE_SRDY_INTERRUPT()   (P2IE &= ~BIT6)
#define HAL_ENABLE_INTERRUPTS()   (_EINT())
#define HAL_DISABLE_INTERRUPTS()   (_DINT())
#define SRDY_INTERRUPT_FALLING_EDGE   0x01
#define SRDY_INTERRUPT_RISING_EDGE   0x00
#define RADIO_ON()   (P3OUT |= BIT7)
#define RADIO_OFF()   (P3OUT &= ~BIT7)
#define SPI_SS_SET()   (P3OUT &= ~(BIT0 | BIT6))
#define SPI_SS_CLEAR()   (P3OUT |= (BIT0 | BIT6))
#define SRDY_IS_HIGH()   (P2IN & BIT6)
#define SRDY_IS_LOW()   ((~P2IN) & BIT6)
#define DEBUG_ON()   (P4OUT |= BIT4)
#define DEBUG_OFF()   (P4OUT &= BIT4)
#define NO_WAKEUP   0
#define WAKEUP_AFTER_TIMER   1
#define WAKEUP_AFTER_ACCELEROMETER   2
#define WAKEUP_AFTER_SRDY   4
#define XTAL   8000000L
#define TICKS_PER_MS   (XTAL / 1000 / 5 - 1)
#define TICKS_PER_US   (TICKS_PER_MS / 1000)
#define VLO_NOMINAL   12000
#define VLO_MIN   (VLO_NOMINAL - (VLO_NOMINAL/4))
#define VLO_MAX   (VLO_NOMINAL + (VLO_NOMINAL/4))
#define GET_MCLK_FREQ()   8000000L
#define LIGHT_SENSOR_ON()   (P2OUT |= BIT1)
#define LIGHT_SENSOR_OFF()   (P2OUT &= ~BIT1)
#define ACCELEROMETER_SS_SET()   (P2OUT &= ~(BIT2|BIT7))
#define ACCELEROMETER_SS_CLEAR()   (P2OUT |= (BIT2|BIT7))
#define ACCELEROMETER_RX_BUF   UCB0RXBUF

Functions

void halInit ()
void delayMs (unsigned int ms)
void delayUs (unsigned int us)
signed int toggleLed (unsigned char led)
signed int setLed (unsigned char led)
void clearLeds ()
void halSpiInitZnp ()
void spiWrite (unsigned char *bytes, unsigned char numBytes)
signed int calibrateVlo ()
signed int initTimer (unsigned char seconds, unsigned char wakeOnTimer)
unsigned int getVcc3 ()
unsigned int getLightSensor ()
void setZnpInterfaceToInputs (void)
signed int halConfigureSrdyInterrrupt (unsigned char flags)
void halSpiInitAccelerometer ()
signed int halEnableAccelerometerInterrupt (unsigned char wakeOnAccelerometer)
unsigned char spiWriteAccelerometer (unsigned char b)

Detailed Description

public methods for hal_cc2530znp_target_board.c

Rev
658
Author
dsmith
Date
2010-07-13 10:23:50 -0700 (Tue, 13 Jul 2010)

YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.


Function Documentation

signed int calibrateVlo (  ) 

Calibrate VLO. Once this is done, the VLO can be used semi-accurately for timers etc. Once calibrated, VLO is within ~2% of actual when using a 1% calibrated DCO frequency and temperature and supply voltage remain unchanged.

Returns:
VLO frequency (number of VLO counts in 1sec), or -1 if out of range
Precondition:
SMCLK is 4MHz
MCLK is 8MHz
ACLK sourced by VLO (BCSCTL3 = LFXT1S_2; in MSP430F2xxx)
Note:
Calibration is only as good as MCLK source. Obviously, if using the internal DCO (+/- 1%) then this value will only be as good as +/- 1%. YMMV.
On MSP430F248 or MSP430F22x2 or MSP430F22x4, must use TACCR2. On MSP430F20x2, must use TACCR0. Check device-specific datasheet to see which module block has ACLK as a compare input. For example, see page 23 of the MSP430F24x datasheet or page 17 of the MSP430F20x2 datasheet, or page 18 of the MSP430F22x4 datasheet.
If application will require accuracy over change in temperature or supply voltage, recommend calibrating VLO more often.
Postcondition:
Timer A settings changed
ACLK divide by 8 bit cleared

Calibrate VLO. Once this is done, the VLO can be used semi-accurately for timers etc. Once calibrated, VLO is within ~2% of actual when using a 1% calibrated DCO frequency and temperature and supply voltage remain unchanged. At room temperature, typical VLO frequencies seen are 9kHz (MSP430F248) and 12kHz (MSP430F2274)

Returns:
VLO frequency (number of VLO counts in 1sec)
Precondition:
SMCLK is 4MHz
MCLK is 8MHz
ACLK sourced by VLO (BCSCTL3 = LFXT1S_2; in MSP430F2xxx)
Note:
calibration is only as good as MCLK source. Obviously, if using the internal DCO (+/- 1%) then this value will only be as good as +/- 1%. YMMV.
on MSP430F248 or MSP430F22x2 or MSP430F22x4, must use TACCR2. On MSP430F20x2, must use TACCR0. Check device-specific datasheet to see which module block has ACLK as a compare input. For example, see page 23 of the MSP430F24x datasheet or page 17 of the MSP430F20x2 datasheet, or page 18 of the MSP430F22x4 datasheet.
if application will require accuracy over change in temperature or supply voltage, recommend calibrating VLO more often.
Postcondition:
Timer A settings changed
ACLK divide by 8 bit cleared
void clearLeds (  ) 

Turns OFF LEDs.

Postcondition:
LEDs are turned off.

Turn off all LEDs

Turns OFF the specified LED. Required for ZNP examples.

Parameters:
led the LED to turn off, must be 0,1,2,3,4.
Returns:
0 if success, -1 if invalid LED specified
void delayMs ( unsigned int  ms  ) 

Blocking Delay in Milliseconds delays by at least the specified number of milliseconds (ms)

Precondition:
TICKS_PER_MS set
Parameters:
ms number of milliseconds to delay
void delayUs ( unsigned int  us  ) 

Blocking Delay in Microseconds delays by at least the specified number of microseconds (us)

Precondition:
TICKS_PER_US set
Parameters:
us number of microseconds to delay
unsigned int getLightSensor (  ) 

Reads the light sensor. Turns on Light sensor, configures ADC, reads the value, and converts it to lux.

Note:
Light sensor outputs current between 0 to 50uA. On the target board, load resistor = 47k Ohms.
0 to 100,000lx will generate 0 to 2350mV input into our ADC.
Light sensor analog input is on P2.0, or analog input A0.
This light sensor is binned for a sensitivity of 27 to 30 uA @ 1000lux = 1269-1410 mV = ADC readings of 520-578counts
Returns:
Light Sensor reading in lux/10.
unsigned int getVcc3 (  ) 

Reads the MSP430 supply voltage using the Analog to Digital Converter (ADC). On CC2530ZNP target board, this is approx. 3600mV

Returns:
Vcc supply voltage, in millivolts

Measures Vcc to the MSP430, nominally 3300mV

  • ADC measures VCC/2 compared to 2.5V reference
  • If Vcc = 3.3V, ADC output should be (1.65/2.5)*4095 = 2703
  • (halfVcc/2.5)*4095 = ADC reading and (Vcc/2.5)*4095 = 2*ADC
  • Vcc*4096 = 5*ADC --> and VCC=5*ADC/4095
Returns:
Vcc in millivolts
signed int halConfigureSrdyInterrrupt ( unsigned char  flags  ) 

Configures SRDY interrupt. Does NOT enable the interrupt. On the CC2530 target board, SRDY is P2.6

Parameters:
flags the options for the SRDY interrupt:

  • SRDY_INTERRUPT_FALLING_EDGE or SRDY_INTERRUPT_RISING_EDGE
  • NO_WAKEUP or WAKEUP_AFTER_SRDY
Returns:
0 if success, -1 if bad flag
signed int halEnableAccelerometerInterrupt ( unsigned char  wakeOnAccelerometer  ) 

Enables the interrupt on the accelerometer (P1.3).

Parameters:
wakeOnAccelerometer whether to wakeup after this int is triggered. Must be either NO_WAKEUP or WAKEUP_AFTER_ACCELEROMETER.
Returns:
0 if success; -1 if invalid wakeOnAccelerometer parameter
void halInit (  ) 

Configures hardware for the particular hardware platform:

  • Ports: sets direction, interrupts, pullup/pulldown resistors etc.
  • Oscillator: turns off WDT, configures MCLK = 8MHz using internal DCO & sets SMCLK = 4MHz
  • Holds radio in reset (active-low)

Configures hardware for the ZNP peripherals

Note:
It takes five clock cycles after SysCtlPeripheralEnable() is called to enable a peripheral before the the peripheral is actually enabled. During this time, attempts to access the peripheral will result in a bus fault. Care should be taken to ensure that the peripheral is not accessed during this brief time period.

Configures hardware for the particular board

  • Oscillator: turns off WDT, configures MCLK & SMCLK
  • Ports: including purpose, direction, pullup/pulldown resistors etc.
  • Holds radio in reset (active-low)
void halSpiInitAccelerometer (  ) 

Initializes the SPI port for the Accelerometer. Required because accelerometer SPI port uses different settings than the ZNP SPI port

void halSpiInitZnp (  ) 

Initializes the Serial Peripheral Interface (SPI) interface to the Zigbee Network Processor (ZNP).

Note:
Maximum CC2530ZNP SPI clock speed is 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
On the CC2530ZNP target board the MSP430 uses USCIB0 SPI port to communicate with the ZNP
Precondition:
SPI pins configured correctly: Clock, MOSI, MISO configured as SPI function; Chip Select configured as an output; SRDY configured as an input.
Postcondition:
SPI port is configured for ZNP communications.

Configures the SPI port for ZNP operation

Precondition:
SPI port configured and is ready for writing
Postcondition:
SPI port is configured for ZNP

Initializes the SPI interface to the ZNP.

Note:
CC2530 SPI clock speed < 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
On MDB the RFIC SPI port is USCIB1
Modify this method for other hardware implementations.
Precondition:
SPI pins configured correctly: Clock, MOSI, MISO configured as SPI function; Chip Select configured as an output; SRDY configured as an input.
Postcondition:
SPI port is configured for RFIC communications.
signed int initTimer ( unsigned char  seconds,
unsigned char  wakeOnTimer 
)

Configures timer.

Precondition:
ACLK sourced from VLO
VLO has been calibrated; number of VLO counts in one second is in vloFrequency.
Parameters:
seconds period of the timer. Maximum is 0xFFFF / vloFrequency; or about 4 since VLO varies between 9kHz - 15kHz. Use a prescaler on timer (e.g. set IDx bits in TACTL register) for longer times. Maximum prescaling of Timer A is divide by 8. Even longer times can be obtained by prescaling ACLK if this doesn't affect other system peripherals.
wakeOnTimer whether to wake the processor after the timer interrupt. Must be either NO_WAKEUP or WAKEUP_AFTER_TIMER.
Returns:
0 if success; -1 if illegal parameter or -2 if VLO not calibrated

Configures timer for source = ACLK

Precondition:
ACLK configured
VLO has been calibrated if using VLO; number of VLO counts in one second is in vloFrequency.
Parameters:
seconds period of the timer. Maximum is 0xFFFF / aClk; about 2 if using 32kHz xtal or about 4 if using VLO since VLO varies between 9kHz - 15kHz. Use a prescaler on timer (e.g. set IDx bits in TACTL register) for longer times. Maximum prescaling of Timer A is divide by 8. Even longer times can be obtained by prescaling ACLK if this doesn't affect other system peripherals.
Returns:
0 if success; -1 if illegal parameter or -2 if aClk not set
signed int setLed ( unsigned char  led  ) 

Turns ON the specified LED.

Parameters:
led the LED to turn on, must be 0 or 1.
Postcondition:
The specified LED is turned on.
Returns:
0 if success, -1 if invalid LED specified

Turn on the specified LED

Turns ON the specified LED. Required for ZNP examples.

Parameters:
led the LED to turn on, must be 0,1,2,3,4.
Returns:
0 if success, -1 if invalid LED specified
void setZnpInterfaceToInputs ( void   ) 

Configures all ZNP interface signals as inputs to allow the ZNP to be programmed. Toggles LED0 quickly to indicate application is running.

void spiWrite ( unsigned char *  bytes,
unsigned char  numBytes 
)

Sends a message over SPI to the ZNP. Based on hal_board.c in CC2480 example application ZASA. The ZNP uses a "write-to-read" approach: to read data out, you must write data in. This is a private method that gets wrapped by other methods, e.g. spiSreq(), spiAreq, etc. To Write, set *bytes and numBytes. To Read, set *bytes only. Don't need to set numBytes because CC2530ZNP will stop when no more bytes are received.

Parameters:
bytes the data to be sent or received.
numBytes the number of bytes to be sent. This same buffer will be overwritten with the received data.
Precondition:
SPI port configured for the ZNP
CC2530ZNP has been initialized
Postcondition:
bytes contains received data, if any

Sends a message over SPI to the radio IC on USCI_B1. Based on hal_board.c in CC2480 example application ZASA. SPI uses a "write-to-read" approach to read data out, you must write data in. This is a private method that gets wrapped by other methods, e.g. spiSreq(), spiPoll(), etc. To Write, set *bytes, numBytes. To Read, set *bytes only. Don't need to set numBytes because CC2530ZNP will stop when no more bytes read.

Parameters:
bytes the data to be sent or received.
numBytes the number of bytes to be sent. This same buffer will be overwritten with the received data.
Note:
Modify this method for other hardware implementations.
Precondition:
SPI port configured for writing
CC2530ZNP has been initialized
Postcondition:
bytes contains received data, if any
See also:
Stellaris Application Note spma002.pdf, "Adding 32kB of Serial SRAM to a Stellaris Microcontroller"

Sends a message over SPI to the radio IC on USCI_B1. Based on hal_board.c in CC2480 example application ZASA. The ZNP uses a "write-to-read" approach to read data out, you must write data in. This is a private method that gets wrapped by other methods, e.g. spiSreq(), spiAreq, etc. To Write, set *bytes, numBytes. To Read, set *bytes only. Don't need to set numBytes because CC2530ZNP will stop when no more bytes read.

Parameters:
bytes the data to be sent or received.
numBytes the number of bytes to be sent. This same buffer will be overwritten with the received data.
Note:
Modify this method for other hardware implementations.
Precondition:
SPI port configured for writing
CC2530ZNP has been initialized
Postcondition:
bytes contains received data, if any
signed int toggleLed ( unsigned char  whichLed  ) 

Toggles the specified LED.

Parameters:
led the LED to toggle, must be 0 or 1.
Postcondition:
The specified LED is toggled.
Returns:
0 if success, -1 if invalid LED specified

Toggles the specified button LED.

Parameters:
whichLed the LED to toggle, must be 0-4.
Postcondition:
The specified button LED is toggled. Status LED is unchanged.
 All Files Functions Variables
Generated on Thu Aug 19 11:48:31 2010 for Hardware Abstraction Layer by  doxygen 1.6.3